<?php
session_start();
include "class.Validator.php";

if(!$_SESSION['username'])
{
    header("Location: index.php");
}

$valid = new Validator();

if($_POST)
{
    if(isset($_POST['vyska']) && $_POST['vyska']&& isset($_POST['vaha']) && $_POST['vaha'] && isset($_POST['beer_count']) && $_POST['beer_count'])
    {
            if(!$valid->validPositiveNumber($_POST['vyska']) )
            {
                    $mess = 'Špatně zadaná výška';	
            }
            if(!$valid->validPositiveNumber($_POST['vaha']))
            {
                    $mess = 'Špatně zadaná vaha';	
            }
            if(!$valid->validPositiveNumber($_POST['beer_count']))
            {
                $mess = 'Špatně zadaný počet piv.';
            }
            if(!$mess)
            {
                $_SESSION['vyska'] = $_POST['vyska'];
                $_SESSION['vaha'] = $_POST['vaha'];
                $_SESSION['beer_count'] = $_POST['beer_count'];
                header('Location: krok3.php');                
            }
    }
    else
    {
        $mess = 'Nebyla vyplněna všechna pole'; 
    }
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Úkol 8</title>
<meta charset="utf-8">
<style>
    body 
    {
        background: #0D48A7;
        font-family: Georgia, Times, serif;
        color: white;
    } 
    #body
    {
        background: #4079D3;
        min-width: 500px;
        width: 70%;
        position: relative;
        margin: 0px auto;
        text-align: center;
    }
    #header
    {
        background: #042D6D;
    }
    #footer
    {
        background: #042D6D;
    }
    table 
    {
        
        margin: 10px auto;
    }
    #menu a
    {
        color: white;
        margin-left: 2em
    } 
</style>
</head>
<body>
    <div id="body">
        <div id="header">
            <h1>WIZZARD</h1>    
        </div>
        <div id ="menu">
            <?php require 'menu.php'; ?>
        </div>
        <div id="content">
        	<h2>Aplikace pro výpočet opilosti</h2>
                <?php if($mess) echo '<p>'.$mess.'</p>'; ?>
        	<form method="post">
                    <table>
                        <tr>
                            <td><label for="vyska"> Výška (cm) </label></td>
                            <td><input type="number" name="vyska" id="vyska"></td>
                        </tr>
                        <tr>
                            <td><label for="vaha"> Váha (kg) </label></td>
                            <td><input type="number" name="vaha" id="vaha"></td>
                        </tr>
                        <tr>
                            <td><label for="beer_count"> Počet piv </label></td>
                            <td><input type="number" name="beer_count" id="beer_count"></td>
                        </tr>
                        <tr>
                            <td colspan="2"><input type="submit" value="Další"></td>
                        </tr>
                    </table>
                </form>
        </div>
        <div id="footer">
            <p>&not;&copy;&sup2; Petr Panoška</p>
        </div>
    </div>
</body>
</html>
